<?php
namespace  Kuka\php;

error_reporting(E_ALL);
require_once __DIR__.'/php/lib/Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;

$GEN_DIR = realpath(dirname(__FILE__)).'/gen-php';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift',__DIR__.'/php/lib');
$loader->registerDefinition('Kuka',$GEN_DIR);
$loader->register();

use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TBufferedTransport;
use Thrift\Exception\TException;

try {
    if (array_search('--http',$argv)) {
        $socket = new THttpClient('192.168.0.21',9090);
    } else {
        $socket = new TSocket('192.168.0.21',9090);
    }
	//设置链接时间
	$socket->setSendTimeout(10000);
	$socket->setRecvTimeout(100000);
	
    $transport = new TBufferedTransport($socket,1024,1024);
    $protocol  = new TBinaryProtocol($transport);
    $client = new \Kuka\KukaServiceClient($protocol);
	
    $transport->open();
	
    echo $client->say("hello");

    $transport->close();
} catch (\Exception $e) {
    print 'TException:'.$e->getMessage().PHP_EOL;
}